require(['./config'], () => {
    require(['pagebar', 'template', 'server', 'nav', 'foot'], (pagebar, template, server) => {
        class Category {
            constructor() {
                this.init()
            }
            init() {
                $.get(server.baseServerUrl + '/api/goods/list', resp => {
                    // bracelets, necklaces, earrings, rings  
                    // let resp = $.respGoods;

                    let parme = window.location.search.slice(1).split('&');
                    let key = parme[0].split('=')[0];
                    let value = parme[0].split('=')[1];
                    let res;

                    if (key == "price") {
                        value = value.split('$')
                        if (value.length == 3) {
                            res = resp.body.list.filter((item) => (item[key] * 1 <= value[2] * 1 && item[key] * 1 >= value[0] * 1));

                        } else {
                            res = resp.body.list.filter((item) => item[key] * 1 >= value[1] * 1);
                        }
                    } else {
                        res = resp.body.list.filter((item) => item[key] == value);
                    }

                    // $('.breadcrumb').append(`<i>&gt;</i> <a href="${window.location.href}">${decodeURIComponent(navtitle)}</a>`);

                    res = res.map(function(item) {
                        if (item.img.indexOf('@') != -1) {
                            item.img = item.img.slice(0, item.img.indexOf('@'))
                        }
                        return item
                    })

                    pagebar.render({ count: res.length, limit: 8, ele: '#category-good-list', list: res, templateid: 'good-list-template' })
                })
            }
        }
        new Category()
    })
})